package com.lisp.clp.parent_first;

import java.net.URL;
import java.net.URLClassLoader;

import com.lisp.clp.box.IBox;

/**
 * commons-logging使用TCCL进行runtime discovery， 从而得出应该用log4j
 * 但实际初始化log4j时，又用了AppClassLoader，所以会抛出异常
 */
public class ParentFirstTestJCL1 
{
    public static void main( String[] args ) throws Exception
    {
        URLClassLoader childClassLoader = new URLClassLoader(
	        new URL[] {
	          new URL("file:lib/log4j-1.2.17.jar"),
	          new URL("file:lib/commons-logging-1.0.4.jar"),
	          new URL("file:lib/"),           // 用于加载log4j.xml
	          new URL("file:target/classes/") // 用于加载com.lisp.clp.box.impl.BoxImplWithJCL
        });
        
        Thread.currentThread().setContextClassLoader(childClassLoader);
        
        Class<?> boxClass = childClassLoader.loadClass("com.lisp.clp.box.impl.BoxImplWithJCL");
	    IBox box = (IBox) boxClass.newInstance();
	    box.print();
    }
}
